package io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * 对象流：处理流/高级流
 * 1）ObjectInputStream和ObjectOutputStream
 * 2)作用：进行对象的序列化和反序列化
 * 3）对象的序列化：将一个java对象转换为一组字节的过程称为对象序列化
 * 4）对象反序列化：将一组字节还原为java对象
 */
public class OOSDemo {
    public static void main(String[] args) throws IOException {
        String name = "赵锐锋";
        int age = 25;
        String gender = "男";
        String[] otherInfo = {"是一名学生","山西太原"};
        Student a= new Student(name,age,gender,otherInfo);
        System.out.println(a);
        /**对象输出流在序列化时，必须保证序列化对象必须实现Serializeable接口*/
        FileOutputStream fos = new FileOutputStream("student.obj");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(a);
        System.out.println("写出完毕");
        oos.close();
    }
}
